package jjn.carl.binary_tree;

import commons.BinaryTreeHelper;
import commons.TreeNode;

import java.util.List;

/**
 * @author Jiang Jining
 * @since 2023-07-15 0:00
 */
public class LeetCode222 {
    public int countNodes(TreeNode root) {
        if (root == null) {
            return 0;
        }
        int leftCount = countNodes(root.left);
        int rightCount = countNodes(root.right);
        return leftCount + rightCount + 1;
    }
    
    public static void main(String[] args) {
        List<Integer> list = List.of(1, 2, 3, 4, 5, 6);
        TreeNode node = BinaryTreeHelper.buildTree(list);
        int countNodes = new LeetCode222().countNodes(node);
        System.out.println("countNodes = " + countNodes);
    }
}
